package com.snail.controller;

import com.snail.model.dto.cart.AddCartRequestDto;
import com.snail.model.pojo.cart.BizCart;
import com.snail.model.pojo.mall.BizProduct;
import com.snail.result.Result;
import com.snail.service.BizCartService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shoppingCart")
public class BizCartController {

    @Autowired
    private BizCartService bizCartService;

   //添加商品到购物车的方法
    @PostMapping("/addToCart")
    public Result addToCart( @RequestBody AddCartRequestDto addCartRequestDto){

        bizCartService.addToCart(addCartRequestDto);
        return Result.success();
    }
    //根据用户id查询购物车
    @GetMapping("/getOrCreateCart")
    public Result getOrCreateCart(Long userId) {
        BizCart bizCart = bizCartService.getOrCreateCart(userId);

        return Result.success(bizCart);
    }


    //根据商品id查询商品
    @GetMapping("/selectById")
    public Result<BizProduct> selectById(@RequestParam Integer productId){
        BizProduct product = bizCartService.selectById(productId);
        return Result.success(product);
    }


}

